<?php

namespace app\home\controller;

use app\home\model\User as UserModel;
use think\Container;
use think\Db;

class DataTest extends Container
{
    public function index()
    {
        # code...
    }
    public function insetr()
    {
        # code...
        $arr = [
            'user' => 'demo02',
            'name' => '似水流年',
            'classes' => '3班',
            'sex' => '男',
            'pic' =>  'localhost:8080/image/tx.webp',
            'time' => date('Y-m-d H:i:s'),
            'qq' => 1006316436,
            'pass' => '123456'
        ];
        $flag = Db::name('user')->data($arr)->insert();
        return $flag;
    }
    public function testCreateTable()
    {
        $sql = <<<sql
    CREATE TABLE `tp_user` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `accound` varchar(255) not null,
    `username` varchar(255),
    `password` varchar(255) not null ,
    `avatar` varchar(255) ,
    `title` varchar(255) default "普通",
    `sign` varchar(255) default "这个人没有签名" COMMENT "签名",
    `usercard` bigint(20) not null COMMENT "学号",
    `school` varchar(10) not null default "清道夫学院" COMMENT "学校",
    `age` int(3) default 2 COMMENT "年龄",
    `staus` int(2) default 0 comment "用户权限",
    `tkoen` text,
    `visitid` int(10) COMMENT "访客id",
    `sex` enum("男","女") default "女",
    `watchcard` varchar(255) COMMENT "微信号",
    `qqcard` int(10) COMMENT "qq号",
    `phone` int(10) COMMENT "手机号",
    `posts` int(10) default 0  COMMENT "帖子数",
    `photos` int(10) default 0 COMMENT "照片数",
    `vlogs` int(10) default 0 COMMENT "vlog数",
    `selflikes` int(10) default 0 COMMENT "赞数",
    `views` int(10) default 0 COMMENT "访客数",
    `comments` int(10) default 0 COMMENT "评论数",
    `logtime` datetime,
    `regtime` datetime,
    PRIMARY KEY (`id`)
    ) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4;
    sql;

        dump(Db::execute($sql));
    }
    public function insert()
    {
        # code...
        // $data = UserModel::select();
        $arr = [
            'accound' => 'admin',
            'username' => '爱吃粽子',
            'password' => 'zyq1392010',
            'avatar' => 'https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png',
            'title' => '管理员',
            'sign' => '做最好的自己',
            'usercard' => 2021103030342,
            'age' => 18,
            'staus' => 2,
            'tkoen' => md5('2021103030342zyq1392010'),
            'logtime' => date('Y-m-d H:i:s'),
            'regtime' => date('Y-m-d H:i:s')
        ];
        $flag = UserModel::insert($arr);
        return json($flag);
    }
    public function creatTableCls()
    {
        # code...
        $sql = <<<sql
        CREATE TABLE `tp_classes` (
        `id` int(11) NOT NULL AUTO_INCREMENT,
        `title` varchar(255) not null comment "帖子标题",
        `content` text,
        `userid` int(10) not null comment "发帖者id",
        `picid` int(10) comment "图片资源id",
        `videoid` int(10) comment "视频id", 
        PRIMARY KEY (`id`)
        ) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4;
        sql;
        dump(Db::execute($sql));
    }
}
/*    */